import { defineStore } from 'pinia'
import { ref } from 'vue'
import { loginApi } from '@/apis/Login'
import { useCartStore } from './CartStore'
export const useUserInfo = defineStore(
  'userStore',
  () => {
    const cartstore = useCartStore()
    const userInfo = ref({})
    const getUserInfo = async ({ account, password }) => {
      const res = await loginApi({ account, password })
      userInfo.value = res.result
    }
    //退出时清除用户信息
    const cleaInfo = () => {
      userInfo.value = {}
      cartstore.cleanCart()
    }
    return {
      userInfo,
      getUserInfo,
      cleaInfo,
    }
  },
  {
    persist: true,
  },
)
